﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;

namespace TabsNavigation.Behaviors
{
    public class CloseActiveTabAction : TargetedTriggerAction<TabControl>
    {
        protected override void Invoke(object parameter)
        {
            if (this.Target == null) return;
            if (this.Target.Items.Count > 0)
            {
                foreach (TabItem _tabItem in this.Target.Items)
                {
                    if (_tabItem.IsSelected)
                    {
                        this.Target.Items.Remove(_tabItem);
                        return;
                    }
                }
            }
        }
    }
}
